package com.wxx.controller;

import com.wxx.pojo.User;
import com.wxx.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result<Object> login(@RequestBody User user, HttpSession httpSession){
        if (user == null || !"123456".equals(user.getPassword())){
            return Result.fail("用户名或密码错误");
        }

        httpSession.setAttribute("currentUser", user.getUsername());
        System.out.println(httpSession);
        return Result.success("登录成功");
    }

    /**
     * 获取用户名
     */
    @GetMapping("/getUsername")
    public Result<String> getUserName(HttpSession httpSession){
        return Result.success((String) httpSession.getAttribute("currentUser"));
    }

}
